package com.yuehuanghun.admin.core.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Transient;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.yuehuanghun.admin.core.config.annotation.mybatislilu.CreateBy;
import com.yuehuanghun.admin.core.config.annotation.mybatislilu.CreateTime;
import com.yuehuanghun.admin.core.config.annotation.mybatislilu.UpdateBy;
import com.yuehuanghun.mybatis.milu.annotation.alias.attr.UpdateTime;
import com.yuehuanghun.mybatis.milu.annotation.alias.id.SnowflakeId;

import lombok.Data;

/**
 * 部门表 sys_dept
 * 
 * @author yadmin
 */
@Data
@Entity
public class SysDept implements Serializable {
	private static final long serialVersionUID = 1L;

	/** 部门ID */
	@SnowflakeId
	@JsonFormat(shape = Shape.STRING)
	private Long deptId;

	/** 父部门ID */
	@JsonFormat(shape = Shape.STRING)
	private Long parentId;

	/** 祖级列表 */
	private String ancestors;

	/** 部门名称 */
	@NotBlank(message = "部门名称不能为空")
	@Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符")
	private String deptName;

	/** 显示顺序 */
	@NotBlank(message = "显示顺序不能为空")
	private String orderNum;

	/** 负责人 */
	private String leader;

	/** 联系电话 */
	@Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符")
	private String phone;

	/** 邮箱 */
	@Email(message = "邮箱格式不正确")
	@Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
	private String email;

	/** 部门状态:0正常,1停用 */
	private String status;

	/** 删除标志（0代表存在 2代表删除） */
	private String delFlag;

	/** 父部门名称 */
	@Transient
	private String parentName;

	/** 创建者 */
	@CreateBy
	private String createBy;

	/** 创建时间 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@CreateTime
	private Date createTime;

	/** 更新者 */
	@UpdateBy
	private String updateBy;

	/** 更新时间 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@UpdateTime
	private Date updateTime;
	
	@ManyToMany
	@JoinTable(name = "sys_role_dept", joinColumns = @JoinColumn(name = "dept_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
	private List<SysRole> roles;

	/** 请求参数 */
	@Transient
    private Map<String, Object> params;

	/** 子部门 */
	@Transient
	private List<SysDept> children = new ArrayList<SysDept>();
	
	public Map<String, Object> getParams() {
		return params == null ? (params = new HashMap<>()) : params;
	}
}
